package com.cxm.helper.util;

import cn.hutool.core.collection.CollUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: chenximeng
 * @date: 2022/11/21 09:11
 */
@Slf4j
public class BeanUtil {

    public static <T> List<T> copyList(List<?> source, Class<T> aClass) {
        if (CollUtil.isEmpty(source)) {
            return null;
        }
        List<T> result = CollUtil.newArrayList();
        try {
            for (Object s : source) {
                T target = aClass.newInstance();
                BeanUtils.copyProperties(s, target);
                result.add(target);
            }
            return result;
        } catch (Exception e) {
            log.error("拷贝list出错", e);
        }

        return null;
    }
}
